﻿<!-- Phan luu lai cac thong tin loc-->
<?php
$v_fisrt= 0;
if(isset($_REQUEST['hdn_fisrt'])){
	$v_fisrt= $_REQUEST['hdn_fisrt']; 
}
//Luu lai category_id ban dau
if(isset($_REQUEST['hdn_back_cate_id']))
	$v_back_cate_id = $_REQUEST['hdn_back_cate_id'];

if(isset($_REQUEST['hdn_back_agency_id']))
	$v_back_agency_id = $_REQUEST['hdn_back_agency_id'];
//Luu lai cac chu cai hay cum tu de loc
if(isset($_REQUEST['hdn_filter']))
{
	$v_filter = $_REQUEST['hdn_filter'];
}
//Luu lai phuong thuc loc
if (isset($_REQUEST['hdn_method']))
{
	$v_method = $_REQUEST['hdn_method'];
}
if (isset($_REQUEST['hdn_status']))
{
	$v_status = $_REQUEST['hdn_status'];
}

if(isset($_REQUEST['hdn_save_and_add_new']))
{
	$v_save_and_add_new = $_REQUEST['hdn_save_and_add_new'];
}
$v_af_id = 0;
if(isset($_REQUEST['hdn_af_id'])){
	$v_af_id = $_REQUEST['hdn_af_id']; 
}
if ($v_af_id >0 ){
	$v_af_id = $rs_single_af['PK_AF'];
	$v_af_code = $rs_single_af['C_CODE'];
	$v_af_name = $rs_single_af['C_NAME'];
	$v_cate_id = $rs_single_af['FK_CATE'];
	$v_agency_id = $rs_single_af['FK_AGENCY'];
	$v_creator_id = $rs_single_af['FK_CREATOR'];
	$v_approver_id = $rs_single_af['FK_APPROVER'];
	$v_content = $rs_single_af['C_CONTENT'];
	$v_valid_date = _yyyymmdd_to_ddmmyyyy($rs_single_af['C_VALID_DATE']);
	$v_count = $rs_single_af['C_VIEWED_NUMBER'];
	$v_status = $rs_single_af['C_STATUS'];
	$v_order = $rs_single_af['C_ORDER'];
	$v_refuse =  $rs_single_af['C_REFUSE'];
	$v_str_status_checked = "";
	if ($v_status==1){
		$v_str_status_checked="checked";
	}
	if(_CONST_INTEGRATE_LDAP){
		$v_creator_name = LDAP_GetCN($v_creator_id);
		$v_aprrover_name = LDAP_GetCN($v_approver_id);
	}else{
		$v_creator_name =_get_item_attr_by_id($_SESSION['arr_all_staff'],$v_creator_id ,'name');
		$v_aprrover_name = _get_item_attr_by_id($_SESSION['arr_all_staff'],$v_approver_id ,'name');
	}
}else {
	$v_cate_id = $v_back_cate_id;
	if(isset($_REQUEST['hdn_cate_id'])){
		$v_cate_id = $_REQUEST['hdn_cate_id'];
	}
	$v_agency_id = $v_back_agency_id;
	if(isset($_REQUEST['hdn_agency_id'])){
		$v_agency_id = $_REQUEST['hdn_agency_id'];
	}
	$v_af_id = 0;
	$v_af_name = "";
	$v_af_content = "";
	$v_valid_date = "";
	$v_order = _get_next_value("T_ONEGATE_AF","C_ORDER","");
	$v_count = 0;
	$v_status = 1;
	$v_str_status_checked="checked";
	$v_creator_id = $_SESSION['staff_id'];
}

//Doan nay dung de tao bo editor DEV-EDITOR
	SetDevEditPath($DEVEDIT_PATH, $DEVEDIT_PATH_FULL	);
	$short_des = new DevEdit();
	$short_des->SetName("txt_detail");
	$short_des->SetLanguage(DE_AMERICAN);
	$short_des->SetPathType(DE_PATH_TYPE_ABSOLUTE);
	$short_des->SetDocumentType(DE_DOC_TYPE_SNIPPET);
	$short_des->EnableGuidelines();
	$short_des->SetTextAreaDimensions("100%","100%");
	$short_des->HideSaveButton();
	//$short_des->SetValue(html_entity_decode( $v_content));
	$short_des->SetValue(( _replace_bad_char($v_content)));
//

if ($v_af_id >0){
	$v_display = "block";	
}else{
	$v_display = "none";
}	
$v_str_save_and_add_new_checked="";
if ($v_save_and_add_new==1){
	$v_str_save_and_add_new_checked="checked";
}	
// Goi thu tuc xu ly khi xoa cac file moi them (chua submit)
$v_goto_url_for_delete_file = "javascript:delete_row(document.all.tr_line_new,document.forms(0).chk_file_attach_new_id,document.forms(0).hdn_deleted_new_file_id_list);";
// Goi thu tuc de them moi dong
$v_goto_url_for_add_file = "javascript:add_row(document.all.tr_line_new," . CONST_AF_UPDATE_DATE_MAXLENGTH .");";
?>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0">
	<tr>
		<td class="large_title" width="100%"><?php 
			if ($v_af_id > 0) echo CONST_AF_UPDATE_TITLE; 
			else echo CONST_AF_ADD_TITLE;?>
		</td>
	</tr>	
</table>
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" border="0" cellpadding="0" cellspacing="0">
	<col width="10%"><col width="40%"><col width="40%">
	<tr><td width="5%"></td></tr>
	<tr>
		<form action="index.php" method="post" enctype= "multipart/form-data" name="f_dsp_single_af">
		<input Type="hidden" Name="fuseaction" value="UPDATE_AF" >		
		<input Type="hidden" Name="hdn_filter" value="<?php echo $v_filter; ?>" >
		<input Type="hidden" Name="hdn_method" value="<?php echo $v_method;?>" >
		<input Type="hidden" Name="hdn_af_id" value="<?php echo $v_af_id;?>" >
		<input Type="hidden" Name="hdn_back_cate_id" value="<?php echo $v_back_cate_id; ?>" >
		<input Type="hidden" Name="hdn_back_agency_id" value="<?php echo $v_back_agency_id; ?>" >
		<input type="hidden" name="hdn_creator_id" value="<?php echo $v_creator_id;?>">
		<input type="hidden" name="hdn_approver_id" value="<?php echo $v_approver_id;?>">
		<input Type="hidden" Name="hdn_cate_id" value="<?php echo $v_cate_id; ?>" >
		<input Type="hidden" Name="hdn_agency_id" value="<?php echo $v_agency_id; ?>" >
		<input Type="hidden" Name="hdn_status" value="<?php echo $v_status; ?>" >
		<input Type="hidden" Name="hdn_status_for_add" value="<?php echo $v_status; ?>" >
		<input Type="hidden" name="hdn_af_count" value="<?php echo $v_count;?>">
		<input type="hidden" name="hdn_save_and_add_new" value="<?php echo $v_save_and_add_new; ?>"> 
		<input type="hidden" name="hdn_file_name" value="<?php echo $v_file_name;?>">
		<input type="hidden" name="hdnContent" value='<? echo trim($v_content);?>'>
		<!---Luu ID cua cac file da co nhung da bi xoa-->
		<input type="hidden" name="hdn_deleted_exist_file_id_list" value="">
		<!---Luu ID cua cac file moi them nhung da bi xoa-->
		<input type="hidden" name="hdn_deleted_new_file_id_list" value="">
		<input type="hidden" name="hdn_chk_refuse" value="">
		<input type="hidden" name="hdn_status_af" value="<?php echo $v_status_af;?>"> 
		<input type="hidden" name="hdn_fisrt" value="<?php echo $v_fisrt;?>">
		<input type="hidden" name="hdn_refuse" value="<?php echo $v_refuse;?>">
	</tr>
	<!--Bang chua cac Thong tin-->
	<tr>
		<td class="normal_label"><?php echo CONST_AF_ID_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td colspan="4"><input Name="txt_af_code"  type="text" class="normal_textbox" style="width:95%" value="<?php echo $v_af_code ?>" maxlength="<?php echo _CONST_AF_CODE_MAXLENGTH; ?>" message="<?php echo CONST_AF_ID_MESSAGE;?>" optional="<?php echo CONST_AF_ID_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<!--Textbox nhap ten loai so lieu -->
	<tr>
		<td class="normal_label"><?php echo CONST_AF_NAME_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td colspan="4"><input Name="txt_af_name" Type="text"  class="normal_textbox" style="width:95%" value="<?php echo $v_af_name; ?>" maxlength="<?php echo _CONST_AF_NAME_MAXLENGTH;?>" message="<?php echo CONST_AF_NAME_MESSAGE;?>" optional="<?php echo CONST_AF_NAME_OPTIONAL;?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_AF_AGENCY_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td colspan="4"><select class= "normal_selectbox" style="width:95%" name = "cbo_af_agency" onChange="change_text(document.forms(0).hdn_agency_id, document.forms(0).cbo_af_agency.value);" message="<?php echo CONST_AF_AGENCY_MESSAGE;?>"  optional = "<?php echo CONST_AF_AGENCY_OPTIONAL; ?>"onKeyDown="change_focus(document.forms(0),this)">
			<option id="",value="-1">--<?php echo CONST_AF_AGENCY ?>--</option>	
			<? echo _generate_select_option($arr_all_agency_creator,"0","0","2", $v_agency_id);?>
		</select></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_AF_CATE_LABEL; ?> <small class="normal_starmark">*</small></td>
		<td colspan="4"><select class= "normal_selectbox" style="width:95%" name = "cbo_af_cate" onChange="change_text(document.forms(0).hdn_cate_id, document.forms(0).cbo_af_cate.value);" message="<?php echo CONST_AF_CATE_MESSAGE;?>"  optional = "<?php echo CONST_AF_CATE_OPTIONAL; ?>"onKeyDown="change_focus(document.forms(0),this)">
			<option id="",value="-1">--<?php echo CONST_AF_CATE ?>--</option>	
			<? echo _generate_select_option($arr_all_cate_creator,"0","0","2", $v_cate_id);?>
		</select></td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_VALID_DATE_LABEL;?> <small class="normal_starmark">*</small>&nbsp;</td>
		<td colspan="4">
			<input type="text" name="txt_valid_date" class="normal_date_textbox" isdate="true" value="<?php echo $v_valid_date;?>" optional="<?php echo CONST_VALID_DATE_OPTIONAL;?>" message="<?php echo CONST_VALID_DATE_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this);">
			<img src="<? echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" border="0" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH; ?>isa-calendar/',document.forms(0).txt_valid_date)" style="cursor:hand;">&nbsp;&nbsp;&nbsp;
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_AF_ORDER_LABEL; ?></td>
		<td colspan="4"><input Name="txt_order" Type="text"  class="short_number_textbox" value="<?php echo $v_order; ?>" maxlength="<?php echo CONST_AF_ORDER_MAXLENGTH;?>" message="<?php echo CONST_AF_ORDER_MESSAGE;?>" optional="<?php echo CONST_AF_ORDER_OPTIONAL;?>" isnumeric="<?php echo CONST_AF_ORDER_ISNUMERIC; ?>" min="<?php echo CONST_AF_ORDER_MIN; ?>" max="<?php echo CONST_AF_ORDER_MAX; ?>" onKeyDown="change_focus(document.forms(0),this)"></td>
	</tr>
	<tr>
		<td class="small_title" colspan="10"><?php echo CONST_AF_CONTENT_LABEL; ?></td>
	</tr>
	<tr>
		<td colspan="5">
			<!-- ~~~~~~~~~~~~~~~~~ ISA Editor    ~~~~~~~~~~~ -->
			<?php 
			$short_des->ShowControl("98%", "400", $IMAGE_NEWS);
			?>	
		</td>
	</tr>
	<tr>
		<td class="small_title" colspan="10"><? echo CONST_AF_FILE_ATTACH_LABEL;?></td>
	</tr>
	<tr>
		<td colspan="5">
			<!--Bang chua cac file dinh kem-->
			<table width="100%" cellpadding="0" cellspacing="0">
				<col width="10%"><col width="2%"><col width="88%">
				<!--Vong lap hien thi cac file da dinh kem van ban--><?
				if(isset($rs_single_af_file)){
					$v_count = sizeof($rs_single_af_file);
				}else{
					$v_count = 0;
				}	
				if ($v_af_id >0 and $v_count>0) {
					// Goi thu tuc xu ly khi xoa cac file da co
					$v_goto_url_for_delete_file = $v_goto_url_for_delete_file . "delete_row(document.all.tr_line_exist,document.forms(0).chk_file_attach_exist_id,document.forms(0).hdn_deleted_exist_file_id_list);";
					for ($i=0; $i<$v_count; $i++) {
						$v_af_file_id = $rs_single_af_file[$i]['0'];
						$v_file_name = $rs_single_af_file[$i]['2']; 
						if(_is_sqlserver()){
							$v_file_url = trim(CONST_AF_URL_PATH_FROM_ROOT) . $v_file_name;
							$v_goto_url = "javascript:filename_onclick('T_ONEGATE_AF_FILE', 'PK_AF_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_af_file_id) . ",'" . $v_file_url ."');" ;
							$target = "";
						}
						?>
						<tr id="tr_line_exist">
							<td>&nbsp;</td>
							<td>
								<input type="checkbox" name="chk_file_attach_exist_id" value="<? echo $v_af_file_id; ?>">&nbsp;
							</td>
							<td>
								<a href="<? echo $v_goto_url; ?>" class="normal_link" <? echo $target;?>><? echo $v_file_name;?></a>
							</td>
						</tr><?
					}
				}?>
				<!--Vong lap hien thi cac file dinh kem se them vao van ban--><?
				for($i=0; $i<CONST_MAX_NUMBER_ATTACH_FILE; $i++){
					
					if ($i<2 And $v_is_granted_update) {
						$v_str_show="block";
					}else{
						$v_str_show="none";
					}?>
					<tr id="tr_line_new" style="display:<? echo $v_str_show;?>;">
						<td>&nbsp;</td>
						<td><input type="checkbox" name="chk_file_attach_new_id" value="<? echo $i; ?>"></td>
						<td>
							<input type="file" name="file_attach<? echo $i;?>" size="80%" class="small_textbox" optional="<? echo CONST_ATTACH_FILE_OPTIONAL;?>">
						</td>
					</tr><?
				}?>
				<!--Cac Button Them va Xoa file dinh kem van ban--><?
				if ($v_is_granted_update) {
					$v_str_show="block";
				}else{
					$v_str_show="none";
				}?>
				<tr align="center" style="display:<? echo $v_str_show;?>;">
					<td colspan="5">
						<a href="<? echo $v_goto_url_for_add_file;?>" class="small_link" ><? echo _CONST_ADD_BUTTON;?></a> &nbsp;
						<a href="<? echo $v_goto_url_for_delete_file;?>" class="small_link"><? echo _CONST_DELETE_BUTTON;?></a>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr style="display:<?php echo $v_display;?>" >
		<td colspan="5">
			<table width="100%" class = "list_table2" cellpadding="0" cellspacing="0">
				<tr class = "header">
					<td width="100%"><?php echo CONST_AF_CONCERN_LIST_TITLE;?></td>
				</tr>	
			</table>	
		</td>
	</tr>
	<tr  style="display:<?php echo $v_display;?>" >
		<td colspan="10" valign="top">
			<IFRAME
				ID=IFrame1
				NAME="if_header"
				FRAMEBORDER=0
				SCROLLING=NO
				HEIGHT = 170pt
				WIDTH = 100%
				ALIGN = BASELINE
				MARGINHEIGHT = 0
				MARGINWIDTH = 0
				SRC="index.php?fuseaction=DISPLAY_ALL_AF_CONCERN&hdn_af_id=<? echo $v_af_id;?>&modal_dialog_mode=1&allow_editing_in_modal_dialog=1"> 
			</IFRAME>
		</td>
	</tr>
	<tr><?php
			if($v_status == 3){?>
			<td class="normal_label"><?php echo CONST_RESOURCE_PLAN_REASON_LABEL;?></td>
			<td colspan=3>
				<textarea name="txt_reason" value ="" class="normal_textarea" rows="4"   readonly optional="true" style="width:90%" message ="<?php echo CONST_REASON_MESSAGE;?>"><?php echo $v_refuse; ?></textarea>
			</td><?php
			}?>
		</tr>
</table>

<!--bang chua cac button-->
<table width="100%" >
	<tr>
		<td align="center" width="100%" height="40" valign="bottom"><?php
			if ($v_is_granted_update && $v_status<>2 && $v_count_creator_af>0){
				 	$v_url_onclick="save_info('UPDATE_AF');";?>
				<input type="button" name="btn_save" class="normal_button" value="<?php  echo _CONST_SAVE_BUTTON;?>" onClick="<?php echo $v_url_onclick;?>" onKeyDown="change_focus(document.forms(0),this);" ><?
			}?>
			<input Type="button" Name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('<?php echo $_GO_BACK?>')" onKeyDown="change_focus(document.forms(0),this)">	
		</td>
	</tr>			
</table>					
</form>
</div>
<script>
reshow_row(document.all.tr_line_exist,document.forms(0).chk_file_attach_exist_id,document.forms(0).hdn_deleted_exist_file_id_list);
reshow_row(document.all.tr_line_new,document.forms(0).chk_file_attach_new_id,document.forms(0).hdn_deleted_new_file_id_list);
//-----------Ham phuc vu cho ISA-EDITOR-------------------
function change_text(p_obj,p_value){
	p_obj.value = p_value;
}
set_focus(document.forms(0));
</script>
